<template>
	<h2>该班级学生进行登分或修改</h2>
	<div>
		<table>
			<tr>
				<th>功能</th>
				<td> <button v-on:click="save()"> 批量提交</button></td>
			</tr>
		</table>

		<br />
		<table border="1" style="width: 100%;">
			<tr>
				<th>学生编号</th>
				<th>学生姓名</th>
				<th>班级编号</th>
				<th>班级名称</th>
				<th>课程编号</th>
				<th>课程名称</th>
				<th>课程成绩</th>
				<th>登分时间</th>
			</tr>
			<tr v-for="c in data.marks">
				<td align="center">{{c.sno}}</td>
				<td align="center">{{c.user.uname}}</td>
				<td align="center">{{c.user.clz.clzno}}</td>
				<td align="center">{{c.user.clz.clzname}}</td>
				<td align="center">{{c.course.cno}}</td>
				<td align="center">{{c.course.cname}}</td>
				<td align="center"><input type="text" v-model="c.score"
						style="width: 50%; height: 20%; text-align: center;" /></td>
				<th>{{c.tpost}}</th>				

			</tr>
		</table>


	</div>
</template>

<script setup>
	import {
		ref,
		reactive,
		onMounted,
		createApp
	} from 'vue';
	import {$get} from '../../ajax';
	import { $postj } from '../../ajax';
	import {
		useRoute
	} from "vue-router";
import myalert from '../../utils/myalert';

	const route = useRoute()


	const data = reactive({
		marks: []
	})

	function save() {
		console.log(data.marks)
		let mks = []
		for (let i = 0; i < data.marks.length; i++) {
			let m = data.marks[i];
		if(m.score!=m.oldscore){
			// console.log(data.marks[i])
			
			let obj = {};
			obj.id = m.id;
			obj.sno = m.sno;
			obj.cno = m.course.cno;
			obj.score = m.score;
			obj.tpost=new Date()
			
			mks.push(obj);
			}
			
		}
		console.log(mks);
		$postj("/api/fore/tea/addMark", mks).then((resp) => {
			 myalert("批量提交成绩成功 ...")
	
		})

	}
	onMounted(() => {
		
		console.log("clzno=" + route.query.clzno)
		console.log("cno+" + route.query.cno)

		$get("/api/fore/tea/findMark?clzno=" + route.query.clzno + "&cno=" + route.query.cno)
			.then((resp) => {
				console.log(resp)
				data.marks = resp.data.data;	
			for (var i = 0; i < data.marks.length; i++) {
			    data.marks[i].oldscore=data.marks[i].score
			}
				console.log(data.marks)
			})
		
	})
</script>

<style>
</style>